package cn.com.lyb.flink.split;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


public class SplitFilterDemo {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);
        DataStreamSource<String> socketDS = env.socketTextStream("172.32.1.6", 1234);

        // 同一个数据要被处理两遍
        SingleOutputStreamOperator<String> even = socketDS.filter((FilterFunction<String>) value -> Integer.parseInt(value) % 2 == 0);

        SingleOutputStreamOperator<String> odd = socketDS.filter((FilterFunction<String>) value -> Integer.parseInt(value) % 2 == 1);
        odd.print("奇数");
        even.print("偶数");

        // --------------------------------

        env.execute();
    }
}
